import 'package:fish_redux/fish_redux.dart';
import 'action.dart';
import 'state.dart';
import '../../../app_files.dart';

Effect<FeedbackViewState> buildEffect() {
  return combineEffects(<Object, Effect<FeedbackViewState>>{
    FeedbackViewAction.action: _onAction,
    FeedbackViewAction.onSubmit: _onSubmit,
  });
}

void _onAction(Action action, Context<FeedbackViewState> ctx) {}

void _onSubmit(Action action, Context<FeedbackViewState> ctx) async {
  if (ctx.state.contentController.text.length == 0) {
    CommonUtils.showErrorInfo(ctx.context, '请输入反馈内容');
    return;
  }
  CommonUtils.closeKey(ctx.context);
  CommonUtils.showLoadingDialog(ctx.context);
  ResultData res = await CommonNetWork.feedBackAdd(
    ctx.state.contentController.text,
    ctx.state.contactController.text,
  );
  Navigator.pop(ctx.context);
  if (res.success) {
    await CommonUtils.showAlertView(ctx.context, '感谢您的反馈');
    Navigator.pop(ctx.context);
  } else {
    CommonUtils.showErrorInfo(ctx.context, res.desc);
  }
}
